package com.hxl.linuxfilemanager.controller;

import com.hxl.linuxfilemanager.anno.ExcludeInterceptor;
import com.hxl.linuxfilemanager.config.LinuxPropertiesConfig;
import com.hxl.linuxfilemanager.entity.R;
import com.hxl.linuxfilemanager.util.ResponseUtils;
import com.hxl.linuxfilemanager.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("api/user")
public class UserController {
    @Autowired
    LinuxPropertiesConfig linuxPropertiesConfig;

    /**
     * 用户登录接口，拦截器不拦截
     * @param model
     * @param userName
     * @param pass
     * @param session
     * @return
     */
    @ExcludeInterceptor
    @PostMapping("login")
    public R userLogin(
            Model model,
            @RequestParam("userName")String userName,
            @RequestParam("userPass")String pass, HttpSession session){
        /**
         * 如果密码和配置文件中的相等
         */
        if (linuxPropertiesConfig.getUserPass().equals(pass) && linuxPropertiesConfig.getUserName().equals(userName)){
            session.setAttribute("login",true);
            return ResponseUtils.suceess("OK","{}");
        }
        return ResponseUtils.error(-1,"用户信息错误");
    }
}
